import java.util.HashMap;
import java.util.Objects;

/**
 * Created by losor on 2016/9/29.
 */


public class _383_Ransom_Note {

    public static void main(String[] args) {
        System.out.println(canConstruct("fihjjjjei","hjibagacbhadfaefdjaeaebgi"));
    }

    public static boolean canConstruct(String ransomNote, String magazine) {
        HashMap map = new HashMap();
        StringBuilder s = new StringBuilder(magazine);
        for (int i = 0; i < s.length(); i++) {
            if (map.containsKey(s.charAt(i))){
                int count = (int)map.get(s.charAt(i)) + 1;
                map.put(s.charAt(i),count);
            }
            else{
                map.put(s.charAt(i),1);
            }
        }
        s = new StringBuilder(ransomNote);
        for (int i = 0; i < s.length(); i++) {
            if (map.containsKey(s.charAt(i))){
                int count = (int)map.get(s.charAt(i)) - 1;
                if (count<0){
                    return false;
                }
                map.put(s.charAt(i),count);
            }
            else{
                return false;
            }
        }
        return true;
    }




//神tm没有理解题意，写的是最小字符串的检索。
//    public static boolean canConstruct(String ransomNote, String magazine) {
//        if (Objects.equals(magazine, "") || magazine == null){
//            return Objects.equals(ransomNote, "") || ransomNote == null;
//        }
//        if (Objects.equals(ransomNote, ""))
//            return true;
//        if (ransomNote.length() > magazine.length()){
//            return false;
//        }
//
//        StringBuilder ransomNoteBuilder = new StringBuilder(ransomNote);
//        StringBuilder magazineBuilder = new StringBuilder(magazine);
//
//        int[][] magazineMap = new int[magazineBuilder.length()][magazineBuilder.length()];
//
//        for (int i = 0; i < magazineBuilder.length(); i++) {
//            for (int j = 0; j < magazineBuilder.length(); j++) {
//                if (i == 0 || j == 0) {
//                    if(i == 0){
//                    if (magazineBuilder.charAt(j) == ransomNote.charAt(0)) {
//                        magazineMap[i][j]++;
//                    }
//                    }
//                    else if (j == 0) {
//                        if (magazineBuilder.charAt(i) == ransomNote.charAt(0)) {
//                            magazineMap[i][j]++;
//                        }
//                    }
//                } else {
//                    int top = 0;
//                    int left = 0;
//                    if (magazineBuilder.charAt(i) == ransomNote.charAt(magazineMap[i - 1][j])) {
//                        top = magazineMap[i - 1][j] + 1;
//                    }
//                    else{
//                        top = magazineMap[i - 1][j];
//                    }
//                    if (magazineBuilder.charAt(j) == ransomNote.charAt(magazineMap[i][j - 1])) {
//                        left = magazineMap[i][j - 1] + 1;
//                    }
//                    else{
//                        left = magazineMap[i][j - 1];
//                    }
//                        magazineMap[i][j] = top > left? top:left;
//
//                }
//
//                if(magazineMap[i][j] == ransomNote.length()){
//                    return true;
//                }
//            }
//        }
//
//        System.out.println(magazineMap[ransomNote.length()-1][ransomNote.length()-1]);
//        return false;
//    }
}


//"fihjjjjei"
//        "hjibagacbhadfaefdjaeaebgi"